import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/http/dio_service.dart';
import 'package:flutter_ncsjqz_getx/model/base_entity.dart';
import 'package:flutter_ncsjqz_getx/page_common/show_video_page.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:get/get.dart';

import 'all_farm2_logic.dart';

class all_farm2Page extends StatefulWidget {
  late String name;
  late int id;
  all_farm2Page({required this.id,required this.name});
  @override
  _all_farm2PageState createState() => _all_farm2PageState();
}

class _all_farm2PageState extends State<all_farm2Page> {
  final all_farm2Logic logic = Get.put(all_farm2Logic());
  BaseEntity indexPageImgListEntity  = BaseEntity();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  getData() async{
     indexPageImgListEntity = await DioService<BaseEntity>().getVideoSurveillance({
      "pageSize": 99,
      "currPage": 1,
      "classifyId": widget.id
    });
     setState(() {

     });
  }
  @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Colors.grey.shade100,
        appBar: appBarWidget(title: "监控列表（${widget.name}）"),
        body: SafeArea(
          child: ListView(
            padding: EdgeInsets.all(15),
            children: [
              Wrap(
                alignment: WrapAlignment.spaceBetween,
                children: List.generate(indexPageImgListEntity.data == null ? 0 : indexPageImgListEntity.data['list'].length, (index) {
                  return InkWell(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Stack(
                          alignment: Alignment.center,
                          children: [
                            Container(
                              width: (Get.width * 0.5) - 22.5,
                              height: ((Get.width * 0.5) - 22.5) * 0.7,
                              color: Colors.white,
                              child: InkWidget.imgNet("${indexPageImgListEntity.data['list'][index]['videoPic']}"),
                            ),
                            Positioned(child: InkWidget.imgAsset('play.png'),width: 50,height: 50,),
                            Positioned(child: InkWidget.text("${indexPageImgListEntity.data['list'][index]['surveillanceId']}",color: Colors.red),bottom: 10,left: 10,)
                          ],
                        ),
                        InkWidget.text("${indexPageImgListEntity.data['list'][index]['deviceName']}"),
                        // InkWidget.text("${indexPageImgListEntity.data['list'][index]['videoAddress']}"),
                      ],
                    ),
                    onTap: (){
                      Get.to(()=>ShowVideoPage(title: "${indexPageImgListEntity.data['list'][index]['deviceName']}",url: "${indexPageImgListEntity.data['list'][index]['videoAddress']}",autoPlay: true,));
                    },
                  );
                }),
              ),
            ],
          ),
        ),
      );
    }

  @override
  void dispose() {
    Get.delete<all_farm2Logic>();
    super.dispose();
  }
}